﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ElCharro01.Models;

namespace ElCharro01.Areas.Admin.Controllers
{
    //[Authorize(Roles = "Administrator")]
    public class ImageController : Controller
    {
        private Entities db = new Entities();

        //
        // GET: /Admin/Image/

        public ViewResult Index()
        {
            return View(db.ImageSet.ToList());
        }


        //
        // GET: /Admin/Image/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Admin/Image/Create

        [HttpPost]
        public ActionResult Create(Image image)
        {
            if (ModelState.IsValid)
            {
                db.ImageSet.AddObject(image);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(image);
        }

        //
        // GET: /Admin/Image/Edit/5

        public ActionResult Edit(int id)
        {
            Image image = db.ImageSet.Single(i => i.ID == id);
            return View(image);
        }

        //
        // POST: /Admin/Image/Edit/5

        [HttpPost]
        public ActionResult Edit(Image image)
        {
            if (ModelState.IsValid)
            {
                db.ImageSet.Attach(image);
                db.ObjectStateManager.ChangeObjectState(image, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(image);
        }

        //
        // GET: /Admin/Image/Delete/5

        public ActionResult Delete(int id)
        {
            Image image = db.ImageSet.Single(i => i.ID == id);
            return View(image);
        }

        //
        // POST: /Admin/Image/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            Image image = db.ImageSet.Single(i => i.ID == id);
            db.ImageSet.DeleteObject(image);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}